#include <iostream>
#include <vector>
#include <ctime>
#include <set>
using namespace std;

class Solution
{
public:
    int maxlength(vector<int> nums)
    {
        int n = nums.size();
        vector<int> dp(n, 1);
        vector<int> maxchild;
        maxchild.push_back(nums[0]);
        for (int i = 1; i < n; i++)
        {
            if (maxchild.back() < nums[i])
            {
                dp[i] = dp[i - 1] + 1;
                maxchild.push_back(nums[i]);
            }
            else if (maxchild.back() > nums[i])
            {
                dp[i] = dp[i - 1];
                maxchild.erase(maxchild.end()-1);
                maxchild.push_back(nums[i]);
            }
            else{
                dp[i] = dp[i-1];
            }
        }
        int maxlength = 0;
        for (int i = 0; i < n; i++)
        {
            maxlength = max(maxlength, dp[i]);
        }
        return maxlength;
    }
};

int main()
{
    Solution sol;
    vector<int> nums = {1, 3, 2, 5, 4, 5};
    cout << sol.maxlength(nums);
}